function ajaxFn(obj) {
  let xhr = new XMLHttpRequest(); //先创建一个ajax对象出来
  let str = "";

  if (obj.params) {
    for (let key in obj.params) {
      str += `${key}=${obj.params[key]}&`;
    }
  }
  str = str.slice(0, str.length - 1);
  console.log(str);
  //get
  if (obj.type == "get") {
    if (str == "") {
      xhr.open("get", obj.url);
      xhr.send();
    } else {
      xhr.open("get", obj.url + "?" + str);
      xhr.send();
    }
  }
  //post
  if (obj.type == "post") {
    xhr.open("post", obj.url);
    xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
    if (obj.author) {
      xhr.setRequestHeader("authorization", localStorage.getItem("token"));
    }
    xhr.send(str);
  }
  //put
  if (obj.type == "put") {
    xhr.open("put", obj.url);
    xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
    xhr.send(str);
  }
  //delete
  if (obj.type == "delete") {
    xhr.open("delete", obj.url);
    xhr.send();
  }
  xhr.onreadystatechange = function () {
    if (xhr.readyState == 4) {
      if (xhr.status == 200) {
        let data = xhr.responseText;
        obj.fn(data);
      }
    }
  };
}
